package ihm;

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.SwingConstants;
import javax.swing.JComboBox;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;

import metier.*;

public class IhmTache {

	private JFrame frmGestionDeCollaborateurs;
	private JLabel lblNumero;
	private JTextField txtNumero;
	private JTextField txtLibelle;
	private JTextField txtJourHomme;
	private JComboBox<Collaborateur> cboMatriculeCollab;
	private JComboBox<Contrat> cboRefContrat;
	private JLabel lblJourHomme;
	private JLabel lblLibelle;
	private JButton btnConfirmer;
	private JButton btnAnnuler;
	
	/**
	 * Launch the application.
	 */
	public void main() {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					new IhmTache();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	
	/**
	 * Create the application.
	 */
	public IhmTache() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frmGestionDeCollaborateurs = new JFrame();
		frmGestionDeCollaborateurs.setTitle("Gestion des tâches");
		frmGestionDeCollaborateurs.setBounds(100, 100, 547, 220);
		frmGestionDeCollaborateurs.setDefaultCloseOperation(JFrame.NORMAL);
		
		lblNumero = new JLabel("Numéro :");
		lblNumero.setHorizontalAlignment(SwingConstants.RIGHT);
		
		lblLibelle = new JLabel("Libellé :");
		lblLibelle.setHorizontalAlignment(SwingConstants.RIGHT);
		
		lblJourHomme = new JLabel("Jour/Homme :");
		lblJourHomme.setHorizontalAlignment(SwingConstants.RIGHT);
		
		txtNumero = new JTextField();
		txtNumero.setColumns(10);
		
		txtLibelle = new JTextField();
		txtLibelle.setColumns(10);
		
		txtJourHomme = new JTextField();
		txtJourHomme.setColumns(10);
		
		btnConfirmer = new JButton("Confirmer");
		btnConfirmer.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
			}
		});
		
		btnAnnuler = new JButton("Annuler");
		btnAnnuler.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				frmGestionDeCollaborateurs.setVisible(false);
			}
		});
		
		JLabel lblMatriculeDuCollaborateur = new JLabel("Matricule du collaborateur :");
		lblMatriculeDuCollaborateur.setHorizontalAlignment(SwingConstants.RIGHT);
		
		JLabel lblRefrenceDuContrat = new JLabel("Référence du contrat :");
		lblRefrenceDuContrat.setHorizontalAlignment(SwingConstants.RIGHT);
		
		cboMatriculeCollab = new JComboBox<Collaborateur>();
		
		cboRefContrat = new JComboBox<Contrat>();
		GroupLayout groupLayout = new GroupLayout(frmGestionDeCollaborateurs.getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(26)
					.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING, false)
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(10)
							.addComponent(lblRefrenceDuContrat, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
						.addComponent(lblMatriculeDuCollaborateur, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblJourHomme, GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE)
						.addComponent(lblLibelle, GroupLayout.PREFERRED_SIZE, 84, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblNumero))
					.addGap(18)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(cboRefContrat, 0, 318, Short.MAX_VALUE)
						.addComponent(cboMatriculeCollab, 0, 318, Short.MAX_VALUE)
						.addGroup(groupLayout.createSequentialGroup()
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addGroup(groupLayout.createSequentialGroup()
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(btnConfirmer)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(btnAnnuler, GroupLayout.DEFAULT_SIZE, 77, Short.MAX_VALUE)
									.addGap(146))
								.addComponent(txtJourHomme, GroupLayout.DEFAULT_SIZE, 310, Short.MAX_VALUE)
								.addComponent(txtLibelle, 310, 310, Short.MAX_VALUE)
								.addComponent(txtNumero, GroupLayout.PREFERRED_SIZE, 310, GroupLayout.PREFERRED_SIZE))
							.addGap(8)))
					.addGap(27))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.TRAILING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap(22, Short.MAX_VALUE)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(txtNumero, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblNumero))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(txtLibelle, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblLibelle))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(txtJourHomme, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblJourHomme))
					.addGap(9)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblMatriculeDuCollaborateur)
						.addComponent(cboMatriculeCollab, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE))
					.addGap(12)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblRefrenceDuContrat, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)
						.addComponent(cboRefContrat, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE))
					.addGap(9)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(btnAnnuler)
						.addComponent(btnConfirmer))
					.addGap(7))
		);
		frmGestionDeCollaborateurs.getContentPane().setLayout(groupLayout);
	}
	
	public void ajouterTache(){
		txtNumero.setText(Integer.valueOf(999).toString());
		txtNumero.setEnabled(false);
		
		frmGestionDeCollaborateurs.setVisible(true);
	}
	
	public void modifierTache(Tache maTache){
		txtLibelle.setText(maTache.getLibelle());
		txtJourHomme.setText(Integer.valueOf(maTache.getChargePreviJoursHomme()).toString());
		txtNumero.setText(Integer.valueOf(maTache.getNumTache()).toString());
		frmGestionDeCollaborateurs.setVisible(true);
	}
	
	public void setCboMatriculeCollab (ArrayList<Collaborateur> uneCollectionCollab) {
		int n = uneCollectionCollab.size();
		for (int i=0; i<n ; i++) {
			cboMatriculeCollab.addItem(uneCollectionCollab.get(i));
		}
	}
	
	public void setCboRefContrat(ArrayList<Contrat> uneListContrat) {
		int n = uneListContrat.size();
		for (int i=0; i<n ; i++) {
			cboRefContrat.addItem(uneListContrat.get(i));
		}
	}
}
